package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.decoration.MammonTypeSwitch;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class MammonTypeSwitchDaoImpl extends TempDao {

    public List<MammonTypeSwitch> getMammonTypeSwitchList(int channelId) {
        ResultSet rs = null;
        CallableStatement call = null;
        List<MammonTypeSwitch> list = new ArrayList<>();
        String sql = "select * from t_s_mammon_type_switch where channelId=?";
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, channelId);
            rs = call.executeQuery();
            while (rs.next()) {
                MammonTypeSwitch data = new MammonTypeSwitch();
                data.setChannelId(rs.getInt("channelId"));
                data.setDecorationId(rs.getInt("decorationId"));
                data.setOpenStatus(rs.getInt("openStatus"));
                list.add(data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }
}
